<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ include file="/static/include/taglib.jsp"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html >
<html>
<head>
 <meta name="viewport" content="width=device-width" />
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  
 <title>后台管理--机构列表</title>
 <link href="${ctxStatic}/layui/css/layui.css" rel="stylesheet" />
 <link href="${ctxStatic}/css/kpiuitanchu.css" rel="stylesheet" />
 <script src="${ctxStatic}/js/jquery-1.8.3.min.js?v=2.0" type="text/javascript"></script>
 <script src="${ctxStatic}/layui/layui.all.js"  type="text/javascript"></script>
 <script src="${ctxStatic}/js/common.js" type="text/javascript"></script>
</head>
<body>
<div class="tanchucontent">
 <div class="layui-form" id="formedit" name="formedit">
   <div class="layui-form-item">
	   <label class="layui-form-label" style="color:#ffffff">选择模板：</label>
	   <div class="layui-input-block">
		  <select id="templateid" name="templateid" lay-verify="required">
                <c:forEach var="item" items="${lsttemp}">
                  <option value="${item.templateid}">${item.templatename}</option>
                </c:forEach>
          </select>
	   </div>   
     </div> 
 </div>
 
 <div style="width:80%;margin:0 auto">
 
  <table style="width:100%">
   <tr>
    <td>所属单位：</td>
    <td>         <div class="layui-form" style="width:200px;display: inline-block;">
		   <select name="szdw" lay-filter="szdw">
		        <option value="0">所有部门</option>
                <c:forEach var="item" items="${orglst}">
                  <option value="${item.orgid}">${item.orgname}</option>
                </c:forEach>
              </select></div>
		  <input type="hidden" id="hidszdw" /></td>
		  <td>姓名：</td>
    <td>
      <input type="text" class="layui-input" id="realname"/>
    </td>
    <td style="text-align: center">
     <input type="button" class="button" value="查询" id="btnquery"  onclick="searchtable()" />
    </td>
   </tr>
  
  </table>
		
		  
		   
 
		  
 </div>
 
 <div>
    <div id="list" class="list" lay-filter="list"></div>
 </div>
 
 <div style="width:100%;text-align: right;margin-top:15px">
  <input type="button" class="button"  value="保存" id="btnsave" />
  <input type="button" class="button"  value="关闭" onclick="top.CloseOpenWindow()" />
 </div>
 
 
 
</div>
 
 <script>
 
var table;

 layui.use(['form','table'], function(){
     var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
     table = layui.table;
    
     form.on('select(szdw)', function (data) { 
  	   $("#hidszdw").val(data.value);
  	   form.render('select');   
     });
     
	 form.render();
	 
	 
	 
	 
	 table.render({
			elem : '#list'
			,height :390
			,url : 'get_list_plyymb' // 数据接口
			,page : true // 开启分页
			,limit : 30
			,id: 'userusasstempeditlist'
			,method:"post"
			,cols : [ [ // 表头
			           {type:'checkbox'},
			           {field : 'rowNum',title : '序号',width : 80,align : 'center'}
			           , {field : 'realname',title : '姓名',width : 120,align : 'center'}
			           , {field : 'sex',title : '性别',width : 80,align : 'center'}
			           , {field : 'userno',title : '警号',width : 150,align : 'center'}
			           , {field : 'cardno',title : '身份证号',width : 170,align : 'center'}
			           , {field : 'orgname',title : '所在单位',width : 170,align : 'center'}
			           , {field : 'zzmm',title : '政治面貌',width : 100,align : 'center'}
		            ] ]
		    ,request:{
				type:'post'
			}
	        ,page:false
			,where:{
				realname: $("#realname").val(),
				szdw:$("#hidszdw").val()
				}
		    ,done: function(res, page, count){
		    	$("[data-field='sex']").children().each(function(index){ 
	            	   var text=$(this).text();
	            	   if(text=="0"){
	            		   $(this).text('男')
	            	   }
	            	   else if(text=="1"){
	            		   $(this).text('女')
	            	   }
	              })  
		    }
		    
		});
	 
	 
	 
	
	 
	 $("#btnsave").click(function(){
		 var checkStatus = table.checkStatus('userusasstempeditlist');
		 var data = checkStatus.data;
		 var length=data.length;
		 if(length==0){
			 alert('请选择人员');
			 return;
		 }
		 var userids='';
		 for(i=0;i<length;i++){
			 userids+=data[i].userid+',';
		 }
	     var templateid=$("#templateid").val();
	     top.frames["iframe"].vUserUsAssTemp.addentityuserusass(userids,templateid);
	 })
	 
 });  
 
 function searchtable(){
	 table.reload('userusasstempeditlist', { 
		  page: {
	        curr: 1 //重新从第 1 页开始
	      }
	 ,page:false
	    ,where: {  
	    	realname: $("#realname").val(),
			szdw:$("#hidszdw").val()
	    }  
	}); 
 }
 </script>
</body>
</html>